package com.hqd.ch03.v28.spel.ast;

public class OpGt extends Operator {
    public OpGt(int startPos, int endPos, SpelNodeImpl... operands) {
        super(">", startPos, endPos, operands);
    }

    @Override
    protected Object getValueInternal(Object left, Object right) {
        if (left instanceof Number && right instanceof Number) {
            Number leftNumber = (Number) left;
            Number rightNumber = (Number) right;
            if (leftNumber instanceof Double || rightNumber instanceof Double) {
                return leftNumber.doubleValue() > rightNumber.doubleValue();
            } else if (leftNumber instanceof Integer || rightNumber instanceof Integer) {
                return leftNumber.intValue() > rightNumber.intValue();
            }
        }
        if (left == null) {
            return right == null ? true : false;
        } else if (right == null) {
            return false;
        }
        if (left instanceof Comparable) {
            return ((Comparable<Object>) left).compareTo(right) > 0;
        }
        return null;
    }
}
